#include <iostream>
#include <string>
#include <unistd.h>
#include <jsoncpp/json/json.h>  //系统只能找到/usr/include/，后面就需要自己包含了


//{a:120,b:"123"}
int main()
{
    Json::Value part1;
    part1["haha"]="haha";
    part1["hehe"]="hehe";


    Json::Value root;
    root["x"]=100;
    root["y"]=200;
    root["oper"]='+';
    root["desc"]="this is a + oper";
    root["test"]=part1;

    //序列化
    //Json::FastWriter w;
    Json::StyledWriter w;

    std::string res=w.write(root);
    std::cout<<res<<std::endl;

    sleep(3);

    std::cout<<"------------------反序列化------------------------"<<std::endl;
    //反序列化
    Json::Value v;
    Json::Reader r;
    r.parse(res,v);  //res反序列化到v中

    int x=v["x"].asInt();
    int y=v["y"].asInt();
    char op=v["oper"].asInt();
    std::string desc=v["desc"].asString();
    Json::Value temp=v["test"];

    std::string s1=temp["haha"].asString();
    std::string s2=temp["hehe"].asString();

    std::cout<<x<<std::endl;
    std::cout<<y<<std::endl;
    std::cout<<op<<std::endl;
    std::cout<<desc<<std::endl;

    std::cout<<s1<<std::endl;
    std::cout<<s1<<std::endl;
    return 0;
}